import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useRouterListStore = defineStore('routerlist', () => {
  const routerList = ref([
    {
      path: '/dashboard',
      meta: {
        title: '工作台'
      }
    },
  ])

  // 获取缓存路由列表
  function getRouterList() {
    return routerList.value
  }

  // 添加路由到缓存列表
  function setRouterList(item) {
    routerList.value.push(item)
  }

  // 删除
  function deleteRouter(index, count) {
    routerList.value.splice(index, count)
  }

  // 重置
  function resetRouter() {
    routerList.value = [{
      path: '/dashboard',
        meta: {
          title: '工作台'
        }
    }]
  }

  return { routerList, getRouterList, setRouterList, deleteRouter, resetRouter }
}, {
    persist: true
})
